package codeTop;

import java.util.Stack;

public class q155 {
    class MinStack {

        int min;
        Stack<Integer> stack;
        Stack<Integer> minStack;
        public MinStack() {
            stack = new Stack<>();
            min = Integer.MAX_VALUE;
            minStack = new Stack();
        }

        public void push(int val) {
            stack.push(val);
            min = Math.min(min,val);
            minStack.push(min);
        }

        public void pop() {
            stack.pop();
            minStack.pop();
            min = minStack.isEmpty()?Integer.MAX_VALUE:minStack.peek();
        }

        public int top() {
            return stack.peek();
        }

        public int getMin() {
            return minStack.peek();
        }
    }
}
